package com.kun.video.ui.pane;

import cn.hutool.core.util.ArrayUtil;
import com.kun.video.context.ContextService;
import com.kun.video.controller.Vlcj;
import com.kun.video.thread.ComThreadPool;
import com.kun.video.ui.ComponentUtil;
import com.kun.video.ui.KunComponent;
import com.kun.video.ui.control.button.KunButton;
import com.kun.video.ui.slider.KunSlider;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 视频播放控制容器
 *
 * @author gzc
 * @since 2025/5/22
 **/
public class VideoControlBox extends HBox implements KunComponent {
    private static final Logger log = LoggerFactory.getLogger(VideoControlBox.class);
    private static final String CSS_CLASS = "video-control-box";

    private ComThreadPool comThreadPool;

    /**
     * 截图功能按钮
     */
    public final KunButton playPauseButton = new KunButton("▶", "开始播放");
    public final KunButton playResetButton = new KunButton("⏹", "重新播放");
    public final KunSlider playProgressSlider = new KunSlider(0, 1, 0);
    public final KunSlider volumeSlider = new KunSlider(0, 100, 100);
    public final Label timeLabel = new Label("00:00:00/00:00:00");
    public final Label speedLabel = new Label("1.0x");
    public final KunSlider speedSlider = new KunSlider(0.5, 2.0, 1.0);

    private Vlcj vlcj;


    public VideoControlBox() {
        initialize();
    }

    @Override
    public Parent getNode() {
        return this;
    }

    @Override
    public String getStyleName() {
        return CSS_CLASS;
    }

    @Override
    public void initStyleClass() {
        KunComponent.super.initStyleClass();
    }

    @Override
    public void initLayout() {
        getChildren().addAll(
                playProgressSlider,
                timeLabel,
                playPauseButton,
                playResetButton,
                new Label("速率:"),
                speedSlider,
                speedLabel,
                new Label("🔊"),
                volumeSlider
        );
    }

    @Override
    public void initStyle() {
        setAlignment(Pos.CENTER);
        setPadding(new Insets(5));
        setSpacing(5);
        HBox.setHgrow(playProgressSlider, Priority.ALWAYS);
        speedSlider.setShowTickLabels(true);
        speedSlider.setSnapToTicks(true);
        volumeSlider.setShowTickLabels(true);
    }

    @Override
    public void initDimensions() {
    }

    @Override
    public void reactiveDimensions(double width, double height) {
    }

    @Override
    public void initListeners() {
    }

    @Override
    public void dispose() {
    }

    @Override
    public void initData() {
        comThreadPool = ContextService.getBean(ComThreadPool.class);

    }


    public void dataPassing(Object... params) {
        if (ArrayUtil.isEmpty(params)) {
            return;
        }
        for (Object param : params) {
            if (param instanceof WritableImage writableImage) {
            }
        }
    }
}